<template>
  <div>
    <!-- 顶部搜索 -->
    <div class="search-row search-box">
      <el-form :inline="true" :model="searchParams" class="demo-form-inline">

        <el-form-item label="人审时间">
          <el-date-picker v-model="timeRange" type="datetimerange" range-separator="至" @change="initDate" start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="success" icon="el-icon-search" @click="handleSearch">查询</el-button>
        </el-form-item>

        <el-form-item>
          <el-button type="success" plain @click="handleReset">重置</el-button>
        </el-form-item>

      </el-form>
    </div>

    <!--table 刷新-->
    <div class="table-conBtn">
      <freshCom @searchList="searchList"></freshCom>
    </div>

    <!--table 列表-->
    <div class="table-box">
      <el-table ref="table" :data="tableData" v-loading="loading" :fit="true" max-height="490" stripe>
        <el-table-column type="index" label="序号">
          <template slot-scope="scope">
            {{ scope.$index | filterPage(pagingParams.pageNum, pagingParams.pageSize) }}
          </template>
        </el-table-column>

        <el-table-column label="类型" prop="contentType" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.contentType | jobTypeFilter }}</span>
          </template>
        </el-table-column>

        <el-table-column label="配文" prop="content" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.content.text" v-html="filterContent(scope.row.content.text)">
              {{ scope.row.content.text }}
            </span>
            <span v-else> --- </span>
          </template>
        </el-table-column>

        <el-table-column label="视图" prop="imgJson" align="center">
          <template slot-scope="scope">
            <listImgShow :imgInfo="scope.row.content.imgJson"></listImgShow>
          </template>
        </el-table-column>

        <el-table-column label="创建时间" prop="createdDate" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.createdDate }}</span>
          </template>
        </el-table-column>

        <el-table-column label="未通过原因" prop="reason" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.reason">{{ scope.row.reason }}</span>
            <span v-else> --- </span>
          </template>
        </el-table-column>

        <el-table-column label="人审时间" prop="manualAuditTime" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.manualAuditTime">{{ scope.row.manualAuditTime }}</span>
            <span v-else> --- </span>
          </template>
        </el-table-column>

        <el-table-column label="审核人" prop="checkUserName" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.checkUserName">{{ scope.row.checkUserName }}</span>
            <span v-else> --- </span>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!--分页-全局组件-->
    <pageCom :searchParams="pagingParams" :total="total" @searchList="searchList"></pageCom>

  </div>
</template>

<script>

import { contentToStr } from '@utils/pubFunction'
import { getActivityList } from '@/api/commentCheck/unpassList'

const jobType = {
  TEXT: { text: '图文'},
  VIDEO: { text: '短视频'}
}

export default {
  msg: '活动帖子',

  data() {
    return {
      total: 0,
      loading: true,

      tableData: [],

      timeRange: [],

      pagingParams: {
        pageNum: 1,
        pageSize: 10
      },

      searchParams: {
        timeType: 'manualTime', // 时间类型
        startTime: '',
        endTime: '',
        manual: 'REJECTED', // 人审状态
        sort: 'manualAuditTime desc', // 人审时间倒序
        userType: 'DAPENGACCOUNT', // 大鹏号
        userValue: '', // 大鹏号
      }
    }
  },

  computed: {
    dpAccount() {
      return this.$route.query.dpAccount
    }
  },

  filters: {
    jobTypeFilter (type) {
      return jobType[type].text
    }
  },

  created() {
    if(this.dpAccount) {
      this.searchParams.userValue = this.dpAccount
    }

    this.searchList()
  },

  methods: {
    initDate(val){
      if(!val){
        this.searchParams.startTime = ''
        this.searchParams.endTime = ''  
      }else{
        this.searchParams.startTime = val[0]
        this.searchParams.endTime = val[1]
      }
    },
    searchList() {
      this.loading = true

      if(this.timeRange) {

        this.searchParams.startTime = this.timeRange[0]
        this.searchParams.endTime = this.timeRange[1]
      }
      
      let params = { ...this.searchParams, ...this.pagingParams }

      getActivityList(params, (res) => {
        this.tableData = res.rows
        this.total = res.total
        this.loading = false
      },(err) => {
        this.$message({
          message: err.message,
          type: 'warning'
        })
      })
    },

    // 过滤返回评论内容
    filterContent(item) {
      return contentToStr(item)
    },

    // 查询
    handleSearch() {
      this.pagingParams.pageNum = 1
      this.searchList()
    },

    // 重置
    handleReset() {
      this.timeRange = []
      this.searchParams.startTime = ''
      this.searchParams.endTime = ''
    }
  }
}
</script>
